/* INCLUSIONS */
#include "LINE_SEARCH.h"

/* FUNCTION BODIES */
void LINE_Spiral_Search(DIRECTION d) {
  uint32_t i = 20000000;
  if(d == CLKW) {
  M1_FORWARD(0x70);
  M2_FORWARD(0x10);
  uint8_t INC = 0x10;
  SensorVals sv = {CALIBRATED, 0x00, 0x00,
                   0x00, 0x00, 0x00};
  
  while (INC <= 0x70) {
    LINE_GetSensors(&sv);
    if (sv.PC0 > 0x0300 ||
        sv.PC1 > 0x0300 ||
        sv.PC2 > 0x0300 ||
        sv.PC3 > 0x0300 ||
        sv.PC4 > 0x0300) {
      LINE_StartFollow(&CFG);
      break;}
    M2_FORWARD(INC);
    while(i--);
    i = 2000000;
    INC++;
  }
}
  else if (d == CCLKW) {
  M2_FORWARD(0x70);
  M1_FORWARD(0x10);
  uint8_t INC = 0x10;
  SensorVals sv = {CALIBRATED, 0x00, 0x00,
                   0x00, 0x00, 0x00};
  
  while (INC <= 0x70) {
    LINE_GetSensors(&sv);
    if (sv.PC0 > 0x0300 ||
        sv.PC1 > 0x0300 ||
        sv.PC2 > 0x0300 ||
        sv.PC3 > 0x0300 ||
        sv.PC4 > 0x0300) {
      LINE_StartFollow(&CFG);
      break;}
    M1_FORWARD(INC);
    while(i--);
    i = 2000000;
    INC++;
  }
  }
}
